#include "base.h"
#include "../ressources/resources.h"

bool cBase::ContinuerApplication=true;
vector<HWND> cBase::lesFenetres(0);
cBase::cBase()
{
    nomAppli="Application";
    hInstance=GetModuleHandle(NULL);
    principale.cbSize=sizeof(WNDCLASSEX);
    principale.style=0;//CS_HREDRAW|CS_VREDRAW;
    principale.lpfnWndProc=winproc;
    principale.cbClsExtra=0;
    principale.cbWndExtra=0;
    principale.hInstance=hInstance;
    principale.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_MYICON));
    principale.hCursor=LoadCursor(NULL,IDC_ARROW);
    principale.hbrBackground=(HBRUSH) (COLOR_3DFACE+1);
    principale.lpszMenuName=NULL;
    principale.lpszClassName=nomAppli;
    principale.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    if(!RegisterClassEx(&principale))
    {
        /*MessageBox(
                  NULL,
                  "Impossible de registrer la class",
                  "Alerte",
                  MB_OK
                );*/
    }
    //else
}



LRESULT CALLBACK cBase::winproc(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
    cBase *Window;
    if(message == WM_NCCREATE)
    {
        Window = (cBase *)((LPCREATESTRUCT)lParam)->lpCreateParams;
        SetWindowLongPtr(hwnd,GWL_USERDATA,(LONG_PTR)Window);
    }
    else
    {
        Window = (cBase *)GetWindowLongPtr(hwnd,GWL_USERDATA);

        if(!Window)
            return DefWindowProc(hwnd,message,wParam,lParam);
    }

    return Window->winprocSimple(hwnd,message,wParam,lParam);

}

LRESULT CALLBACK cBase::winprocSimple(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
    return OnCommand(hwnd,message,wParam,lParam);
}

int cBase::OnResizing(HWND fenetre)
{
    return 0;
}

int cBase::OnCommand(HWND hwnd,UINT message,WPARAM wparam,LPARAM lParam)
{
    return 0;
}

int cBase::OnClose()
{
    return 0;
}

int cBase :: BeforeResize(MINMAXINFO* lParam)
{
    return 0;
}


